/*
 Copyright (C) 2013 Yuyao Liang

 This source code is release under the BSD License.

 This program is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE.  See the license for more details.
 
 Create at 9:40:10 AM on Sep 6, 2013.

 */
package com.googlecode.stereoplot;

/**
 * @author lianyuy
 *
 */
import java.awt.*;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.ColorBar;
import org.jfree.chart.plot.dial.*;
import org.jfree.data.general.DefaultValueDataset;
import org.jfree.ui.GradientPaintTransformType;
import org.jfree.ui.StandardGradientPaintTransformer;

public class DialDemo2 extends JFrame {
	static class DemoPanel extends JPanel implements ChangeListener {
		DefaultValueDataset dataset1;
		DefaultValueDataset dataset2;
		StereoPlotDataSeries stereoSeries;
		String zAxisLabel = "Color Values";
		private ColorBar zColorBar = null;

		public void stateChanged(ChangeEvent changeevent) {
		}

		public DemoPanel() {
			super(new BorderLayout());
			dataset1 = new DefaultValueDataset(10D);
			dataset2 = new DefaultValueDataset(50D);
			this.zColorBar = new ColorBar(zAxisLabel);
			StereoDialPlot dialplot = new StereoDialPlot(createStereoSeries(),
					zColorBar);
			zColorBar.setMinimumValue(75);
			zColorBar.setMaximumValue(180);

			dialplot.setView(0.0D, 0.0D, 1.0D, 1.0D);
			dialplot.setDataset(0, dataset1);
			dialplot.setDataset(1, dataset2);

			StereoPlotDialFrame standarddialframe = new StereoPlotDialFrame();
			standarddialframe.setBackgroundPaint(Color.lightGray);
			standarddialframe.setForegroundPaint(Color.darkGray);
			dialplot.setDialFrame(standarddialframe);

			StereoPlotLayer stereoPlotLayer = new StereoPlotLayer(zColorBar);
			stereoPlotLayer.setPaint(Color.blue);
			dialplot.addLayer(stereoPlotLayer);

			StereoGridLayer stereoGridLayer = new StereoGridLayer();
			stereoGridLayer.setPaint(Color.red);
			dialplot.addLayer(stereoGridLayer);

			StereoPlotBoreholeLayer blayer = new StereoPlotBoreholeLayer(
					0 * Math.PI / 180, 10 * Math.PI / 180);
			blayer.setPaint(Color.pink);
			dialplot.addLayer(blayer);

			StereoPlotSelectionLayer selectionLayer = new StereoPlotSelectionLayer();
			dialplot.addLayer(selectionLayer);

			JFreeChart jfreechart = new JFreeChart(dialplot);
			jfreechart.setTitle("Dial Demo 2");
			StereoPlotChartPanel chartpanel = new StereoPlotChartPanel(
					jfreechart);
			chartpanel.setPreferredSize(new Dimension(500, 600));
			chartpanel.addChartMouseListener(selectionLayer);
			chartpanel.addChartMouseDragListener(selectionLayer);
			
			JPanel jpanel = new JPanel(new GridLayout(1, 2));

			add(chartpanel);
			add(jpanel, "South");
		}
	}

	public DialDemo2(String s) {
		super(s);
		setDefaultCloseOperation(3);
		setContentPane(createDemoPanel());
	}

	public static JPanel createDemoPanel() {
		return new DemoPanel();
	}

	private static StereoPlotDataQuickSeries createStereoSeries() {
		double[] data = new double[] { 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
				77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
				77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,

				79, 78, 79, 79, 78, 78, 79, 79, 80, 79, 80, 79, 79, 78, 78, 79,
				79, 78, 79, 78, 79, 79, 78, 78, 79, 79, 80, 79, 80, 79, 79, 78,
				78, 79, 79, 78, 79,

				81, 81, 81, 82, 82, 83, 84, 85, 86, 85, 86, 85, 84, 83, 82, 82,
				81, 81, 81, 81, 81, 82, 82, 83, 84, 85, 86, 85, 86, 85, 84, 83,
				82, 82, 81, 81, 81,

				83, 84, 84, 86, 88, 92, 97, 103, 110, 115, 110, 103, 97, 92,
				88, 86, 84, 84, 83, 84, 84, 86, 88, 92, 97, 103, 110, 115, 110,
				103, 97, 92, 88, 86, 84, 84, 83,

				87, 87, 89, 91, 96, 104, 117, 143, 180, 180, 180, 143, 117,
				104, 96, 91, 89, 87, 87, 87, 89, 91, 96, 104, 117, 143, 180,
				180, 180, 143, 117, 104, 96, 91, 89, 87, 87,

				89, 89, 91, 96, 101, 112, 129, 156, 180, 180, 180, 156, 129,
				112, 101, 96, 91, 89, 89, 89, 91, 96, 101, 112, 129, 156, 180,
				180, 180, 156, 129, 112, 101, 96, 91, 89, 89,

				89, 90, 93, 97, 105, 116, 132, 152, 180, 180, 180, 152, 132,
				116, 105, 97, 93, 90, 89, 90, 93, 97, 105, 116, 132, 152, 180,
				180, 180, 152, 132, 116, 105, 97, 93, 90, 89,

				91, 92, 94, 99, 106, 118, 132, 148, 168, 180, 168, 148, 132,
				118, 106, 99, 94, 92, 91, 92, 94, 99, 106, 118, 132, 148, 168,
				180, 168, 148, 132, 118, 106, 99, 94, 92, 91,

				91, 92, 94, 99, 107, 118, 132, 147, 162, 173, 162, 147, 132,
				118, 107, 99, 94, 92, 91, 92, 94, 99, 107, 118, 132, 147, 162,
				173, 162, 147, 132, 118, 107, 99, 94, 92, 91,

				91, 91, 95, 99, 107, 119, 131, 147, 161, 171, 161, 147, 131,
				119, 107, 99, 95, 91, 91, 91, 95, 99, 107, 119, 131, 147, 161,
				171, 161, 147, 131, 119, 107, 99, 95, 91, 91 };

		return StereoPlotDataSeriesFactory.createStereoPlotDataQuickSeries(
				"StereoPlotDataSeries", SymmetryType.None, 1.169370651, 37, 10,
				data);
	}

	public static void main(String args[]) {
		DialDemo2 dialdemo2 = new DialDemo2("JFreeChart - Dial Demo 2");
		dialdemo2.pack();
		dialdemo2.setVisible(true);
	}
}
